package com.yixiu.study.juc.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 * @CalssName T02_HowToCreateThread
 * @Description
 * @Author yixiu
 * @Date 2021/6/23 19:20
 * @Verison num1.0
 **/
public class T02_HowToCreateThread {

    /**
     * 创建线程的三种方式
     */

    static class MyThread extends Thread {
        @Override
        public void run(){
            System.out.println("Hello MyThread!");
        }
    }

    static class MyRun implements Runnable{

        @Override
        public void run() {
            System.out.println("Hello MyRun!");
        }
    }

    static class MyCall implements Callable<String>{

        @Override
        public String call() throws Exception {
            System.out.println("Hello MyCall!");
            return "SUC";
        }
    }

    /**
     * 启动线程的5种方式
     */

    public static void main(String[] args) {
        new MyThread().start();
        new Thread(new MyRun()).start();
        new Thread(() -> {
            System.out.println("Hello Lambda!");
        }).start();

        Thread t = new Thread(new FutureTask<String>(new MyCall()));
        t.start();

        ExecutorService service = Executors.newCachedThreadPool();
        service.execute(() -> {
            System.out.println("Hello ThreadPool!");
        });
        service.shutdown();
    }


}
